package com.example.javatwo.mapper.cg.tzl;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.javatwo.pojo.cg.lmx.Product;
import com.example.javatwo.pojo.cg.tzl.PanDian;
import com.example.javatwo.pojo.cg.tzl.PanDianXiang;

public interface PanDianMapper {

	@Select("select count(1) from pandian")
	int findzong();

	// 详表查询
	@Select("select * from pandianxiang where BillNo =#{BillNo}")
	List<PanDianXiang> findAll(@Param("BillNo") String BillNo);

	// 主表查询
	@Select("select * from pandian order by billno desc LIMIT #{currentPage},1")
	List<PanDian> findZhuAll(@Param("currentPage") int currentPage);

	// 新增主表
	@Insert("insert into temp.pandian (BillNo, AdjustDate, WareName, IncSubjectName, DecSubjectName, VoucherNO, SalesName, DepartName, Maker, Permitter, SHState, SCState) values(#{BillNo}, #{AdjustDate}, #{WareName}, #{IncSubjectName}, #{DecSubjectName}, #{VoucherNO}, #{SalesName}, #{DepartName}, #{Maker}, #{Permitter}, #{SHState}, #{SCState});")
	void insertzhu(PanDian pandian);

	// 新增详表
	@Insert("insert into temp.pandianxiang (ProdID, ProdName, ProdSize, StdUnitName, SumCurQty, SumCheckQty, SumQty, SuggestPrice, SumCost, Pihao, Yuanyin, BillNo) values( #{ProdID}, #{ProdName}, #{ProdSize}, #{StdUnitName}, #{SumCurQty}, #{SumCheckQty}, #{SumQty}, #{SuggestPrice}, #{SumCost}, #{Pihao}, #{Yuanyin}, #{BillNo});")
	void insertxiang(PanDianXiang pandianxiang);

	// 删除主表
	@Delete("delete from temp.pandian where BillNo = #{BillNo}")
	void delZhu(@Param("BillNo") String BillNo);

	// 删除详表
	@Delete("delete from temp.pandianxiang where BillNo = #{BillNo}")
	void delXiang(@Param("BillNo") String BillNo);
	
	@Update("update pandian set SHState = '已审核' where BillNo = #{BillNo}")
	//修改盘点主表状态
	void updatePanDian(PanDian p);
	
	@Insert("insert into product(prodId,prodName,callAmt)values("
			+ "#{ProdID},#{ProdName},#{SumCheckQty})")
	//新增库存记录
	void insertProduct(PanDianXiang PanDianXiang);
	
	@Update("update pandian set SHState = '未审核' where BillNo = #{BillNo}")
	//修改盘点主表状态
	void updatePanDian2(PanDian p);
	
	@Delete("delete from product where prodId = #{ProdID}")
	//新增库存记录
	void deleteProduct(PanDianXiang PanDianXiang);
	
	//按物料编号查询
	@Select("select * from product where ProdID = #{ProdID}")
	Product findproduct(@Param("ProdID") String ProdID);
	
	//修改库存数量
	@Update("update temp.product set callAmt = #{SumCheckQty} where prodId = #{ProdID} ;")
	void updateProduct(@Param("ProdID") String ProdID,@Param("SumCheckQty") String SumCheckQty);
}
